package com.hongkzh.www.look.presenter;

import com.hongkzh.www.look.model.bean.CategoryBean;
import com.hongkzh.www.look.model.bean.CityAdvBean;
import com.hongkzh.www.look.model.bean.CityBean;
import com.hongkzh.www.look.model.bean.HotAdvBean;
import com.hongkzh.www.look.model.bean.StaticBean;
import com.hongkzh.www.look.model.bean.DayIntegralBean;
import com.hongkzh.www.other.okhttp.CallBackUtil;
import com.hongkzh.www.other.okhttp.OkhttpUtil;
import com.hongkzh.www.look.view.iview.LKIView;
import com.hongkzh.www.presenter.BasePresenter;

import okhttp3.Call;

import static com.hongkzh.www.other.api.Api.*;

/**
 * 乐看
 */
public class LKPresenter extends BasePresenter<LKIView> {
    private int pageNumber = 1;
    private boolean lastPage = false;

    public LKPresenter findDayIntegral(String uid) {
        OkhttpUtil.okHttpPost(FINDDAYINTEGRAL(uid), new CallBackUtil<DayIntegralBean>() {
            @Override
            public void onFailure(Call call, Exception e) {
                getIView().onError(e);
            }

            @Override
            public void onResponse(DayIntegralBean response) {
                getIView().setDayIntegral(response);
            }
        });
        return this;
    }

    public LKPresenter getCarouselList() {
        OkhttpUtil.okHttpPost(GETCAROUSELLIST, new CallBackUtil<StaticBean>() {
            @Override
            public void onFailure(Call call, Exception e) {
                getIView().onError(e);
            }

            @Override
            public void onResponse(StaticBean response) {
                getIView().setCarouselList(response);
            }
        });
        return this;
    }

    public LKPresenter getCategoryList() {
        OkhttpUtil.okHttpPost(GETCATEGORYLIST, new CallBackUtil<CategoryBean>() {
            @Override
            public void onFailure(Call call, Exception e) {
                getIView().onError(e);
            }

            @Override
            public void onResponse(CategoryBean response) {
                getIView().setCategoryList(response);
            }
        });
        return this;
    }

    public LKPresenter getRecommendList() {
        OkhttpUtil.okHttpPost(GETRECOMMENDLIST, new CallBackUtil<CityAdvBean>() {
            @Override
            public void onFailure(Call call, Exception e) {
                getIView().onError(e);
            }

            @Override
            public void onResponse(CityAdvBean response) {
                getIView().setCityAdvList(0, response);
            }
        });
        return this;
    }

    public LKPresenter getStaticList() {
        OkhttpUtil.okHttpPost(GETSTATICLIST, new CallBackUtil<StaticBean>() {
            @Override
            public void onFailure(Call call, Exception e) {
                getIView().onError(e);
            }

            @Override
            public void onResponse(StaticBean response) {
                getIView().setStaticList(response);
            }
        });
        return this;
    }

    public LKPresenter getEnterpriseList() {
        OkhttpUtil.okHttpPost(GETENTERPRISELIST, new CallBackUtil<CityAdvBean>() {
            @Override
            public void onFailure(Call call, Exception e) {
                getIView().onError(e);
            }

            @Override
            public void onResponse(CityAdvBean response) {
                getIView().setCityAdvList(1, response);
            }
        });
        return this;
    }

    public LKPresenter getMediaList() {
        OkhttpUtil.okHttpPost(GETMEDIALIST, new CallBackUtil<CityAdvBean>() {
            @Override
            public void onFailure(Call call, Exception e) {
                getIView().onError(e);
            }

            @Override
            public void onResponse(CityAdvBean response) {
                getIView().setCityAdvList(2, response);
            }
        });
        return this;
    }

    public LKPresenter getCityAdvList() {
        OkhttpUtil.okHttpPost(GETCITYADVLIST, new CallBackUtil<CityAdvBean>() {
            @Override
            public void onFailure(Call call, Exception e) {
                getIView().onError(e);
            }

            @Override
            public void onResponse(CityAdvBean response) {
                getIView().setCityAdvList(3, response);
            }
        });
        return this;
    }

    public LKPresenter getCityList() {
        OkhttpUtil.okHttpPost(GETCITYLIST, new CallBackUtil<CityBean>() {
            @Override
            public void onFailure(Call call, Exception e) {
                getIView().onError(e);
            }

            @Override
            public void onResponse(CityBean response) {
                getIView().setCityList(response);
            }
        });
        return this;
    }

    public LKPresenter getTraditionList() {
        OkhttpUtil.okHttpPost(GETTRADITIONLIST, new CallBackUtil<CityAdvBean>() {
            @Override
            public void onFailure(Call call, Exception e) {
                getIView().onError(e);
            }

            @Override
            public void onResponse(CityAdvBean response) {
                getIView().setCityAdvList(4, response);
            }
        });
        return this;
    }

    public LKPresenter getHotAdvList() {
        OkhttpUtil.okHttpPost(GETHOTADVLIST(String.valueOf(pageNumber)), new CallBackUtil<HotAdvBean>() {
            @Override
            public void onFailure(Call call, Exception e) {
                getIView().onError(e);
            }

            @Override
            public void onResponse(HotAdvBean response) {
                lastPage = response.getData().isLastPage();
                if (lastPage) getIView().onLastPage(lastPage);
                getIView().setHotAdvList(response);
            }
        });
        return this;
    }

    public void loadmore() {
        if (!lastPage) {
            pageNumber += 1;
            getHotAdvList();
        }
    }
}
